<template>
  <div :id="id"></div>
  <!-- 绑定ID -->
</template>

<script>
import './china.js'
// import JSON from './datas/json/chongqing.json';
export default {
  data () {
    return {
      myChart: {}
    }
  },

  props: ['echartObj', 'id'],

  created () {
    this.$nextTick(() => {
      this.loadEchart()
    })
  },
  mounted () {
    const _this = this
    window.addEventListener('resize', () => {
      setTimeout(() => {
        _this.myChart.resize()
      }, 100)
    })
  },
  methods: {
    loadEchart () {
      console.log(this.$echarts)
      this.myChart = this.$echarts.init(document.getElementById(this.id))
      // this.myChart.setOption({
      //   //  这些属性看你传过来的对象中需要哪些自己添加就好
      //   legend: this.echartObj.legend,
      //   color: this.echartObj.color,
      //   series: this.echartObj.series?this.echartObj.series:[],
      //   tooltip: this.echartObj.tooltip,
      //   grid: this.echartObj.grid,
      //   xAxis: this.echartObj.xAxis,
      //   yAxis: this.echartObj.yAxis,
      //   radar: this.echartObj.radar,
      //   title: this.echartObj.title,
      //   visualMap: this.echartObj.visualMap?this.echartObj.visualMap:[],
      //   toolbox: this.echartObj.toolbox,
      // })
      this.myChart.setOption(this.echartObj)
    }
  }
}
</script>
